<template>
  <div class="AdendDialog">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-row>
        <el-col :span="24">
          <el-form-item label="数据名称" prop="dataName">
            <el-input v-model="ruleForm.dataName" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="数据类型" prop="dataType">
            <el-input v-model="ruleForm.dataType" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="所属行业" prop="industry">
            <el-input v-model="ruleForm.industry"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="来源" prop="source">
            <el-input v-model="ruleForm.source"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="状态" prop="status">
            <el-switch v-model="ruleForm.status" active-color="#13ce66" inactive-color="#ff4949">
            </el-switch>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
        <el-button @click="resetForm('ruleForm')">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    props: {
      ranklist: {
        type: Function,
        default: null
      },
      close: {
        type: Function,
        default: null
      }
    },
    data() {
      return {
        ruleForm: {
          dataName: "",
          dataType: "",
          industry: "",
          source: "",
          status: false,
        },
        rules: {
          dataName: [{
            required: true,
            message: "请填写数据名称",
            trigger: "blur",
          }, ],
          dataType: [{
            required: true,
            message: "请输入数据类型",
            trigger: "blur",
          }, ],
          industry: [{
            required: true,
            message: "请输入所属行业",
            trigger: "blur",
          }, ],
          source: [{
            required: true,
            message: "请输入数据来源",
            trigger: "blur",
          }]
        },
        options: [{
            value: "早上9:30",
            label: "早上9:30",
          },
          {
            value: "中午12:00",
            label: "中午12:00",
          },
          {
            value: "下午17:00",
            label: "下午17:00",
          },
        ],
        userArr: [],
      };
    },
    methods: {
      // 表单提交
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$server
              .addList({
                ...this.ruleForm,
                status: this.ruleForm.status ? 1 : 0,
              })
              .then((res) => {
                this.$message({
                  type: "success",
                  message: "添加成功!",
                });
              });
            this.close()
            this.ranklist()
            for (let obj in this.ruleForm) {
              this.ruleForm[obj] = ''
            }
          } else {
            // console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.close()
      },
    }
  }
</script>

<style>

</style>
